/**
 * @class OffScene
 *
 * This class contains all functions needed to parse and represent a given
 * OFF file. OffScene is one of many possible IScene implementations.
 * IScene is our abstract model of a scene and is used by GlWidget to draw it.
 *
 * @see IScene
 * @author B. Stauder
 * @author M. Caputo
 * @date 2010-03-17
 */

#ifndef OFFSCENE_H
#define OFFSCENE_H

#include <QColor>
#include <QVector>
#include <QString>
#include <QStringList>

#include "IScene.h"
#include "CPolygon.h"

class OffScene : public IScene
{

public:
	OffScene(const QString & fileName);
	
	bool isColored() const;
	int polygonsCount() const;
	const CPolygon & polygon(int i) const;

private:
	// Opens a file and reads from it to create a OffScene
	void parseFile(const QString & fileName);

	// Reads the next line (removes all comments
	// and jumps over empty or comment-only lines)
	QString readNextLine(QTextStream *stream);
	
	// Split at whitespaces and ommit the empty parts
	QStringList split2Token(QString *string);
	
	// Create a (colored) vertex from a list of tokens
	CVertex* readVertex(QStringList *tokens);
	
	// Create a (colored) polygon from alist of tokens
	CPolygon readPolygon(QStringList *tokens, CVertex **vertices);
	
	// Read RGB colors (with optinal alpha) from a list of tokens
	QColor readColor(QStringList *tokens, int offset);
	
	// Levels a list of double values between 0 and 255 to a range between 0 and 1
	void levelColorValues(double *values, int count);
	
	// Comparison for transparency sorting
	static bool alphaChannelCompare(const CPolygon & p1, const CPolygon & p2);
	
	bool colored;
	QVector<CPolygon> polygons;
	
};

#endif
